package com.zhengxyou.jetpackdemo.dataBinding;

import com.zhengxyou.jetpackdemo.BR;

import androidx.annotation.DrawableRes;
import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;

public class User extends BaseObservable {
    private String firstName;
    private String lastName;
    @Bindable
    public int age;
    private String disPlayName;

    private String headerUrl;
    @DrawableRes
    private int headerId;
    private long bir;
    public ObservableField<String> fullName = new ObservableField<>();
    public ObservableInt sex = new ObservableInt();

    public User(String firstName, String lastName, int age) {
        this.firstName = firstName;
        this.age = age;
        this.lastName = lastName;
    }

    public int getAge() {
        return age;
    }

    @Bindable
    public String getFirstName() {
        return firstName;
    }

    @Bindable
    public String getLastName() {
        return lastName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
//        notifyPropertyChanged(BR.firstName);
        //更新所有字段
        notifyChange();
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
        //只更新本字段
        notifyPropertyChanged(BR.lastName);
    }

    public void setAge(int age) {
        this.age = age;
        notifyPropertyChanged(BR.age);
    }

    public String getDisPlayName() {
        return disPlayName;
    }

    public void setDisPlayName(String disPlayName) {
        this.disPlayName = disPlayName;
    }

    public String getHeaderUrl() {
        return headerUrl;
    }

    public void setHeaderUrl(String headerUrl) {
        this.headerUrl = headerUrl;
    }

    @Bindable
    public int getHeaderId() {
        return headerId;
    }

    public void setHeaderId(int headerId) {
        this.headerId = headerId;
        notifyPropertyChanged(BR.headerId);
    }

    @Bindable
    public long getBir() {
        return bir;
    }

    public void setBir(long bir) {
        this.bir = bir;
        notifyPropertyChanged(BR.bir);
    }
}
